package com.QK.cnstudy;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ListView;

import com.QK.cnstudy.adapter.ResultAdapter;
import com.QK.cnstudy.db.DBManager;
import com.QK.cnstudy.entity.Stat;

public class StatActivity extends Activity {

    ResultAdapter adapter = null;

    private DBManager dbManager;
    private List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

    private ListView statListView;

    final Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {

        }
    };

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.stat);
        dbManager = CnStudyApp.app.dbManager;
        getView();

        setListViewData();
        adapter = new ResultAdapter(this, list, mHandler);
        statListView.setAdapter(adapter);
    }

    public void setListViewData() {

        Stat stat = dbManager.getStat();
        addToMapList("学习文章", stat.getStudy_work_num() + "");
        addToMapList("阅读次数", stat.getRead_num() + "");
        addToMapList("学习时长", stat.getStudy_time() + "");
        addToMapList("测试总数", stat.getTest_num() + "");
        addToMapList("测试总题数", stat.getTest_subject_num() + "");
        addToMapList("正确率", stat.getTest_wrong_subject_num() + "");
        addToMapList("提示使用次数", stat.getUse_hint_num() + "");
        addToMapList("上次小测时间", stat.getLast_test_time() + "");

    }

    public void addToMapList(String key, String value) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("flag", ResultAdapter.FLAG_TITLE);
        map.put("key", key);
        map.put("value", value);
        list.add(map);
    }

    public void getView() {
        statListView = (ListView) findViewById(R.id.stat_list);
    }
}
